var page = sm("do_Page");
var app = sm("do_App");
var nf = sm("do_Notification");
var hashdata = mm("do_HashData");
var external = sm("do_External");
var root = ui("$");
var http = require("helper/http");
var adUrl = require("url/ad");
var openHelper = require("helper/open");
var gridview = ui("gridview");
var gridData = mm("do_ListData");
var shareUtil = require("helper/share");
gridview.bindItems(gridData);
var href = "";

//andriod返回键
page.on("back", function() {
    app.closePage();
});

page.on("loaded", function(){
	loadPage();
});

var headerAout = ui("headerAout");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
var labelTitle = ui(addheader+".labelTitle");
//左上角-返回
var headerLeft = ui(addheader+".headerLeft");
var headerRight = ui(addheader + ".headerRight");
var imgNext = ui(addheader + ".imgNext");
imgNext.source = "source://image/share/share.png";
imgNext.visible = true;
var header = ui("header");
header.bindData(hashdata);
hashdata.addData({
    "labelTitle" : "广告详情"
})
header.refreshData();
var addShare = root.add("share","source://view/reuse/share.ui", 0, 0);
var shareContent;
var shareId;
var shareImage;
var shareTitle;
headerRight.on("touch", "", 3000, function() {
	page.fire("onShare",{showView:"true",shareTitle:shareTitle,shareContent:shareContent,shareId:shareId,shareType:shareUtil.type.AD,shareImage:shareImage});
});

headerLeft.on("touch", function() {
    app.closePage();
});
var href;
function loadPage(){
	var data = page.getData();
	var id = data.id;
	http.post(adUrl.url.base.detail, {'id':id}, function(data) {
		var detail = data.detail;
		if(detail.pathTitleImg){
			ui("do_ImageView_2").source = detail.pathTitleImg;
		}else{
			ui("do_ImageView_2").source = detail.pathTitleImg;
		}
		labelTitle.text = detail.title; 
		ui("labelRContent").text = detail.content;
		shareContent=detail.content;
		shareTitle=detail.title;
		shareId=detail.id;
		shareImage=detail.pathImg;
		href = detail.href;
		//resume resumeImg
		/*详情图片*/
		gridData.addData(detail.imgItems);
		gridview.refreshItems();
	});
};

ui("do_ALayout_1").on("touch",function(){
	if(href){
		if(href.indexOf("http://")<0){
			href="http://"+href;
		}
		external.openURL(href);
	}
});